package com.ljx.designMode.singleMode;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2022/11/7 10:34
 * @Version 1.0
 */
public class SingleModeTest {
	public static void main(String[] args) {
		// 饿汉模式
		/*SingleModeHungry instance = SingleModeHungry.getInstance();
		SingleModeHungry instance1 = SingleModeHungry.getInstance();
		SingleModeHungry instance2 = SingleModeHungry.getInstance();
		System.out.println(instance);
		System.out.println(instance1);
		System.out.println(instance2);*/

		// 懒汉模式(可能出现线程安全问题)
		/*new Thread(new Runnable() {
			@Override
			public void run() {
				SingleModeLazy instance = SingleModeLazy.getInstance();
				System.out.println(instance);
			}
		}).start();
		new Thread(new Runnable() {
			@Override
			public void run() {
				SingleModeLazy instance = SingleModeLazy.getInstance();
				System.out.println(instance);
			}
		}).start();*/

		// 懒汉模式解决安全问题
		new Thread(new Runnable() {
			@Override
			public void run() {
				SingleModeLazySafe instance = SingleModeLazySafe.getInstance();
				System.out.println(instance);
			}
		}).start();
		new Thread(new Runnable() {
			@Override
			public void run() {
				SingleModeLazySafe instance = SingleModeLazySafe.getInstance();
				System.out.println(instance);
			}
		}).start();
	}
}
